import * as API from '@/services';
import {
  KfBackendEnumPicker,
  DEFAULT_FORM_LAYOUT,
  KfBizQuickFormProps,
  KfFloatingContextProps,
  KfInput,
  KfQuickForm,
  KfTextArea,
} from 'kf-web-library';
import {Form} from 'antd';
import React, {FunctionComponent} from 'react';

const FormItem = Form.Item;
type QueryEntity = API.NotifyRemind;
type CreateEntity = API.NotifyRemind_Create;
type ModifyEntity = API.NotifyRemind_Modify;

type DataFormProps = {} & KfBizQuickFormProps & KfFloatingContextProps;

/**
 * 通知提醒 表单
 */
const QuickForm: FunctionComponent<DataFormProps> = (props) => {
  const {formType, bizId, ...rest} = props;

  return (
    <KfQuickForm
      formType={formType}
      formProps={{
        ...DEFAULT_FORM_LAYOUT,
      }}
      defaultQueryRequest={() =>
        API.queryNotifyRemind(bizId!).then((resp) => {
          if (resp.flag) {
            resp.data = {
              ...resp.data,
            };
          }
          return new Promise((resolve) => resolve(resp));
        })
      }
      submitRequest={{
        create: (formValues) => API.createNotifyRemind({...formValues} as CreateEntity),
        modify: (formValues) => API.modifyNotifyRemind({...formValues, id: bizId} as ModifyEntity),
      }}
      {...rest}
    >
      <FormItem name={nameof<ModifyEntity>((x) => x.name)} label="名称" rules={[{required: true}]}>
        <KfInput/>
      </FormItem>
      <FormItem name={nameof<ModifyEntity>((x) => x.code)} label="编码" rules={[{required: true}]}>
        <KfInput/>
      </FormItem>
      <FormItem name={nameof<ModifyEntity>((x) => x.description)} label="备注" rules={[{required: false}]}>
        <KfTextArea/>
      </FormItem>
    </KfQuickForm>
  );
};

export default QuickForm;
